/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "FLIP核心.h"




S_FLIP物理引擎核心::S_FLIP物理引擎核心() {

}

S_FLIP物理引擎核心::~S_FLIP物理引擎核心() {

}

S_FluidCube* f_flip_创建流体单元(uint32 分辨率, float32 扩散度, float32 粘度, float32 时间步长) {
	S_FluidCube* cube = (S_FluidCube*)malloc(sizeof(S_FluidCube));
	

	uint64 总数量 = 分辨率 * 分辨率 * 分辨率;

	cube->m_域属性.m_单元属性.m_分辨率 = { 分辨率 , 分辨率 , 分辨率};
	cube->m_域属性.m_单元属性.m_单元大小 = cube->m_域属性.m_单元属性.m_世界大小.x / cube->m_域属性.m_单元属性.m_分辨率.x;
	cube->m_域属性.m_Mask = (uint8*)calloc(总数量, sizeof(uint8));


	//cube->m_分辨率 = 分辨率;
	cube->m_扩散量 = 扩散度;
	cube->m_粘度 = 粘度;
	cube->m_时间步长 = 时间步长;

	
	cube->m_速度 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_密度 = (float32*)calloc(总数量, sizeof(float32));

	//cube->m_方向 = (vec3*)calloc(总数量, sizeof(vec3));
	//cube->m_方向0 = (vec3*)calloc(总数量, sizeof(vec3));
	cube->m_方向X = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Y = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Z = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向X0 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Y0 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Z0 = (float32*)calloc(总数量, sizeof(float32));
	
	return cube;
}

void f_flip_销毁流体单元(S_FluidCube* cube) {
	free(cube->m_速度);
	free(cube->m_密度);
	//free(cube->m_方向);
	//free(cube->m_方向0);
	free(cube->m_方向X);
	free(cube->m_方向Y);
	free(cube->m_方向Z);
	free(cube->m_方向X0);
	free(cube->m_方向Y0);
	free(cube->m_方向Z0);

	free(cube);
}

void f_flip_分配单元(S_FluidCube* cube) {
	uint64 总数量 = cube->m_域属性.m_单元属性.m_分辨率.x * cube->m_域属性.m_单元属性.m_分辨率.y * cube->m_域属性.m_单元属性.m_分辨率.z;



	cube->m_速度 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_密度 = (float32*)calloc(总数量, sizeof(float32));

	//cube->m_方向 = (vec3*)calloc(总数量, sizeof(vec3));
	//cube->m_方向0 = (vec3*)calloc(总数量, sizeof(vec3));
	cube->m_方向X = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Y = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Z = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向X0 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Y0 = (float32*)calloc(总数量, sizeof(float32));
	cube->m_方向Z0 = (float32*)calloc(总数量, sizeof(float32));

}
